/*
 * @文件描述: 
 * @版本: 
 * @作者: 周晨阳
 * @Date: 2021-08-17 09:59:58
 */
#include "DAC.h"
#ifdef  WIN_SIM
/*
 * @文件描述: DAC模块设置
 * @版本: 
 * @作者: 周晨阳
 * @Date: 2021-01-16 00:16:24
 */
#include "DAC.h"
/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/
//比例系数
#define _K (4096.0f / DAC_REF_VOLTAGE)
/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/
static uint8_t DAC_1_state = DISABLE;
static uint8_t DAC_2_state = DISABLE;
/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/

/* Public functions ---------------------------------------------------------*/
static void My_DAC_Test(void)
{
    while (1)
    {
        setDAC_Voltage(DAC_1, 2.3f);
    }
}
void My_DAC_Init(void)
{


    openDAC(DAC_1);
    setDAC_Voltage(DAC_1, 0);
    //My_DAC_Test();
}
/**
 * @brief : 设置DAC输出的电压
 * @param {uint8_t} which DAC_1 或DAC_2
 * @param {float} voltage 电压，浮点数
 * @return {*}
 */
void setDAC_Voltage(uint8_t which, float voltage)
{
    uint16_t value;
    if (which == DAC_1 && DAC_1_state == ENABLE)
    {
        //DAC_SetChannel1Data(DAC_Align_12b_R, (uint16_t)(_K * voltage)); //12位右对齐数据格式设置DAC值
        printf("current actual TrigVol:%f\n", voltage);
    }
    else if (which == DAC_2 && DAC_2_state == ENABLE)
    {
        //DAC_SetChannel2Data(DAC_Align_12b_R, (uint16_t)(_K * voltage)); //12位右对齐数据格式设置DAC值
    }
}
/**
 * @brief : 开启DAC
 * @param {uint8_t} which
 * @return {*}
 */
void openDAC(uint8_t which)
{
    if (which == DAC_1)
    {
        // DAC_Cmd(DAC_Channel_1, ENABLE); //使能DAC通道1

        // DAC_SetChannel1Data(DAC_Align_12b_R, 0); //12位右对齐数据格式设置DAC值
        DAC_1_state = ENABLE;
    }
    else if (which == DAC_2)
    {
        // DAC_Cmd(DAC_Channel_2, ENABLE); //使能DAC通道1

        // DAC_SetChannel1Data(DAC_Align_12b_R, 0); //12位右对齐数据格式设置DAC值
        DAC_2_state = ENABLE;
    }
}
/**
 * @brief : 关闭DAC
 * @param {uint8_t} which
 * @return {*}
 */
void closeDAC(uint8_t which)
{
    if (which == DAC_1)
    {
        // DAC_Cmd(DAC_Channel_1, DISABLE); //使能DAC通道1
        DAC_1_state = DISABLE;
    }
    else if (which == DAC_2)
    {
        // DAC_Cmd(DAC_Channel_2, DISABLE); //使能DAC通道1
        DAC_2_state = DISABLE;
    }
}
#endif